#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 1e5 + 10;

int rt[N],sg[N],c[N],n;
vec G[N],ans;

namespace Trie {
	int val[N << 5],ch[N << 5][2],ndn,tg[N << 5],dep[N << 5];
	vec trash;
	int newwd() { int x; return trash.size() ? x = trash.back(),trash.pop_back(),x : ++ndn; }
	int newd() { int x = newwd(); ch[x][0] = ch[x][1] = val[x] = tg[x] = 0; return x; }
	void modix(int x,int v) {
		if(dep[x] < 0) return; if(v >> dep[x] & 1) swap(ch[x][0],ch[x][1]); tg[x] ^= v;
	}
	void pushdn(int x) { if(tg[x]) modix(ch[x][0],tg[x]), modix(ch[x][1],tg[x]), tg[x] = 0; }
	void upd(int &x,int v,int dep) {
		if(!x) x = newd(),Trie :: dep[x] = dep; if(dep == -1) return val[x] = 1,void();
		if(v >> dep & 1) upd(ch[x][1],v,dep - 1); else upd(ch[x][0],v,dep - 1);
		val[x] = val[ch[x][0]] & val[ch[x][1]];
	}
	int mex(int x) {
		if(!x || dep[x] < 0) return 0; pushdn(x);
		if(val[ch[x][0]]) return mex(ch[x][1]) | 1 << dep[x];
		else return mex(ch[x][0]);
	}
	void merge(int &x,int y) {
		if(!x || !y) return x = x | y, void(); if(dep[x] < 0) return val[x] |= val[y],void(); pushdn(x); pushdn(y);
		merge(ch[x][0],ch[y][0]); merge(ch[x][1],ch[y][1]); val[x] = val[ch[x][0]] & val[ch[x][1]]; trash.pb(y);
	}
}

void dfs(int x,int p) {
	int v = 0;
	for(auto y : G[x])
		if(y ^ p) {
			dfs(y,x); v ^= sg[y];
		}
	for(auto y : G[x])
		if(y ^ p) {
			Trie :: modix(rt[y],v ^ sg[y]); Trie :: merge(rt[x],rt[y]);
		}
	if(!c[x]) Trie :: upd(rt[x],v,20);
	sg[x] = Trie :: mex(rt[x]);
}

void dfs1(int x,int p,int v) {
	for(auto y : G[x]) if(y ^ p) v ^= sg[y];
	if(!c[x] && !v) ans.pb(x);
	for(auto y : G[x])
		if(y ^ p)
			dfs1(y,x,v ^ sg[y]);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; for(int i = 1;i <= n;i++) c[i] = in;
	for(int i = 1,u,v;i < n;i++) u = in,v = in,G[u].pb(v),G[v].pb(u);
	dfs(1,0); dfs1(1,0,0);
	if(!sg[1]) puts("-1");
	else { sort(ans.begin(),ans.end()); for(auto y : ans) printf("%d ",y); puts(""); }
	return 0;
}
